/*
 * @Author: moeWang
 * @Date: 2022-03-04 15:55:42
 * @LastEditTime: 2022-03-07 16:48:19
 * @LastEditors: moeWang
 * @Description:
 * @FilePath: \nest-web\src\logical\accessory\entity\accessory.entity.ts
 */

import { ApiPropertyOptional } from '@nestjs/swagger';
import * as moment from 'moment';
import {
  Column,
  Comment,
  DataType,
  Model,
  PrimaryKey,
  Table,
} from 'sequelize-typescript';

@Table({
  tableName: 'rp_accessory',
  timestamps: false,
  comment: '附件表',
})
export class AccessoryEntity extends Model<AccessoryEntity> {
  @ApiPropertyOptional({ description: '主键' })
  @Comment('id')
  @PrimaryKey
  @Column({
    primaryKey: true,
    type: DataType.BIGINT,
  })
  id: string;

  @ApiPropertyOptional({ description: '附件名' })
  @Comment('附件名')
  @Column({
    type: DataType.CHAR,
    field: 'file_name',
  })
  fileName: string;
  @ApiPropertyOptional({ description: '大小' })
  @Comment('大小')
  @Column({
    type: DataType.CHAR,
  })
  size: string;
  @ApiPropertyOptional({ description: '后缀名' })
  @Comment('后缀名')
  @Column({
    type: DataType.CHAR,
    field: 'suffix_name',
  })
  suffixName: string;
  @ApiPropertyOptional({ description: '文件数据' })
  @Comment('文件数据')
  @Column({
    type: DataType.BLOB,
  })
  detail: Buffer;

  @ApiPropertyOptional({ description: '创建人' })
  @Comment('创建人')
  @Column({
    field: 'creator_id',
  })
  creatorId: string;

  @ApiPropertyOptional({ description: '创建时间' })
  @Comment('创建时间')
  @Column({
    get() {
      const date = this.getDataValue('createDate');
      return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : '';
    },
    field: 'create_date',
  })
  createDate: Date;
}
